TicketMaster API 2
Benifits of builder class
- Easier to use because you don’t need to call a constructor with long parameter list
- Easier to implement because you don’t need to provide constructors with different combinations of private fields.
TicketMasterAPI.java
Add getAddress
1 | /** |
Add getImageURL
1 | // {"images": [{"url": "www.example.com/my_image.jpg"}, ...]} |
Add getCategories
1 | // {"classifications" : [{"segment": {"name": "music"}}, ...]} |
Add getItemList
1 | // Convert JSONArray to a list of item objects. |
Modify Search()
1 | /** |
Modify doGet() in searchItem Servlet
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
double lat = Double.parseDouble(request.getParameter("lat"));
double lon = Double.parseDouble(request.getParameter("lon"));
String keyword = request.getParameter("term");
TicketMasterAPI tmAPI = new TicketMasterAPI();
List<Item> items = tmAPI.search(lat, lon, keyword);
JSONArray array = new JSONArray();
try {
for (Item item : items) {
JSONObject obj = item.toJSONObject();
array.put(obj);
}
} catch (Exception e) {
e.printStackTrace();
}
RpcHelper.writeJSONArray(response, array);
}